package com.whq.thrift.api.web.admin.service.config.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.config.ErrorCode;
import com.whq.thrift.api.web.admin.db.config.ErrorCodeMapper;
import com.whq.thrift.api.web.admin.service.config.ErrorCodeService;

@Service
public class ErrorCodeServiceImpl implements ErrorCodeService {
	@Autowired
	private ErrorCodeMapper errorCodeMapper;

	public void addRecord(ErrorCode record) {
		DataSourceContextHolder.set("dataSourceConfig");
		if(record==null){
			return;
		}
		Date now=new Date();
		record.setCreateTime(now);
		this.errorCodeMapper.addRecord(record);
	}

	public List<ErrorCode> findRecordsByMap(Map<String, Object> whereParams, int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceConfig");
		if(whereParams==null){
			whereParams=new HashMap<String, Object>(0);
		}
		whereParams.put("beginIndex", beginIndex);
		whereParams.put("maxCount", maxCount);
		return this.errorCodeMapper.getSelectRecordByMap(whereParams);
	}

	public void updateRecord(ErrorCode record) {
		DataSourceContextHolder.set("dataSourceConfig");
		if(record==null){
			return;
		}
		Date now=new Date();
		record.setUpdateTime(now);
		this.errorCodeMapper.updRecord(record);
	}

	public void deleteRecord(String id) {
		DataSourceContextHolder.set("dataSourceConfig");
		this.errorCodeMapper.delRecord(id);
	}

	public int findRecordCount(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceConfig");
		return this.errorCodeMapper.getSelectCountByKey(whereParams);
	}

	public ErrorCode findRecordByKey(String id) {
		DataSourceContextHolder.set("dataSourceConfig");
		return this.errorCodeMapper.getSelectRecordByKey(id);
	}

	public List<ErrorCode> findRecrodAll() {
		DataSourceContextHolder.set("dataSourceConfig");
		return this.errorCodeMapper.getSelectRecordAll();
	}

}
